import select from "common/constants/select.js";

export default {
	name: "add-permission",
	data() {
		return {
			action: "add",
			colWidth: 11,
			formItems: [
				{label: "编号", kind: "input", prop: "id", isEdit: false, disabled: true},
				{label: "权限编码", kind: "input", prop: "code", isEdit: false, disabled: false},
				{label: "权限等级", kind: "select", prop: "level", isEdit: true, disabled: false, selectOptions: this.constants.select.permissionOptions},
				{label: "权限名称", kind: "input", prop: "name", isEdit: true, disabled: false},
				{label: "权限描述", kind: "textarea", prop: "description", isEdit: true, disabled: false, colWidth: 22, style: {width: "91.6%"}}
			],
			formParams: {}
		};
	},
	created() {
		this.initData(this.$route);
	},
	methods: {
		handleSave(formParams) {
			this.formParams = formParams;
			console.log(this.formParams);
		},
		handleReset() {
			this.formParams = {};
		},
		initData(route) {
			this.formParams = this.formHandler.handleParams(route);
			this.action = this.formHandler.handleAction(route);
			this.formHandler.updateEditStatus(this.action, this.formItems);
		}
	},
	watch: {
		//监听路由的变化来实现添加或切换tab
		$route(to) {
			this.initData(to);
		}
	}
};
